package com.tencent.iov.cowin.befsale.clue.controller.cus;

import com.tencent.iov.cowin.befsale.clue.controller.clue.vo.request.CusUnbindRequest;
import com.tencent.iov.cowin.befsale.clue.controller.clue.vo.response.CusUnbindResponse;
import com.tencent.iov.cowin.befsale.clue.controller.cus.assembler.DealerCustomerAssembler;
import com.tencent.iov.cowin.befsale.clue.controller.cus.vo.request.AddDealerCustomerRequest;
import com.tencent.iov.cowin.befsale.clue.controller.cus.vo.request.DeleteDealerCustomerRequest;
import com.tencent.iov.cowin.befsale.clue.controller.cus.vo.request.QueryCustomerRequest;
import com.tencent.iov.cowin.befsale.clue.controller.cus.vo.request.UpdateCustomerRequest;
import com.tencent.iov.cowin.befsale.clue.controller.cus.vo.response.CustomerResponse;
import com.tencent.iov.cowin.befsale.clue.controller.cus.vo.response.CustomerWithExtResponse;
import com.tencent.iov.cowin.befsale.clue.dao.http.mdquery.response.CustomerBaseResponse;
import com.tencent.iov.cowin.befsale.clue.domain.cus.po.DealerCustomer;
import com.tencent.iov.cowin.befsale.clue.service.cus.DealerCustomerService;
import com.software.boot.common.entity.Response;
import com.software.boot.common.model.dao.PageRequest;
import com.software.boot.common.model.dao.PageResponse;
import com.software.common.config.SearchLocalHeader;
import com.software.common.enums.SCRMRequestHeaderEnum;
import com.software.common.utils.BasePropertyInjection;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Describe: 经销商客户表主表+客户好友关联表_Controller层
 * @author: xiamu
 * @created: 2021-12-21 17:29:53
 * @version: 1.0
 */
@RestController
@RequestMapping(value = "/v1/befsale/dealerCustomer", produces = MediaType.APPLICATION_JSON_VALUE)
@Api(tags = "经销商客户表主表+客户好友关联表_Controller层")
public class DealerCustomerController {

    @Autowired
    private DealerCustomerService dealerCustomerService;

    /**
     * 通过ID获取详细信息
     *
     * @param: id
     * @return: DealerCustomer对象
     */
    @ApiOperation(value = "DealerCustomer管理-通过ID获取详细信息接口", httpMethod = "GET", response = Response.class, notes = "get_detail_by_id")
    @RequestMapping(path = "/get_detail_by_id", method = RequestMethod.GET)
    public Response<CustomerResponse> getDetailById(@ApiParam(required = true, value = "对象ID", defaultValue = "1") @RequestParam("id") Long id) {
        return Response.success(dealerCustomerService.getDetailById(id));
    }

    /**
     * 单条数据插入DealerCustomer
     *
     * @param request
     * @return 插入的条数
     */
    @ApiOperation(value = "DealerCustomer管理-添加信息接口", httpMethod = "POST", response = Response.class, notes = "add")
    @RequestMapping(path = "/add", method = RequestMethod.POST)
    public Response<Long> add(@Valid @RequestBody AddDealerCustomerRequest request) {
        return Response.success(dealerCustomerService.insert(request));
    }

    /**
     * 批量插入DealerCustomer
     *
     * @param requests
     * @return 批量插入的条数
     */
    @ApiOperation(value = "DealerCustomer管理-批量插入DealerCustomer接口", httpMethod = "POST", response = Response.class, notes = "add_batch")
    @RequestMapping(path = "/add_batch", method = RequestMethod.POST)
    public Response<Integer> addBatch(@Valid @RequestBody List<AddDealerCustomerRequest> requests) {
        return Response.success(dealerCustomerService.insertBatch(DealerCustomerAssembler.transformPOToResponseVoList(requests, DealerCustomer.class)));
    }

    /**
     * 通过ID修改信息接口
     *
     * @param: request
     * @return: 修改的条数
     */
    @ApiOperation(value = "DealerCustomer管理-修改信息接口", httpMethod = "POST", response = Response.class, notes = "update")
    @RequestMapping(path = "/update", method = RequestMethod.POST)
    public Response<Integer> update(@Valid @RequestBody UpdateCustomerRequest request) {
        return Response.success(dealerCustomerService.update(request));
    }

    /**
     * 通过ID删除数据
     *
     * @param request
     * @return 删除的条数
     */
    @ApiOperation(value = "DealerCustomer管理-通过ID删除接口", httpMethod = "POST", response = Response.class, notes = "delete")
    @RequestMapping(path = "/delete", method = RequestMethod.POST)
    public Response<Integer> delete(@Valid @RequestBody DeleteDealerCustomerRequest request) {
        return Response.success(dealerCustomerService.delete(request));
    }

    /**
     * 根据条件查询对象list列表
     *
     * @param request
     * @return 查询结果
     */
    @ApiOperation(value = "DealerCustomer管理-根据条件查询对象list列表接口", httpMethod = "POST", response = Response.class, notes = "query_list_by_param")
    @RequestMapping(path = "/get_list_by_param", method = RequestMethod.POST)
    public Response<List<CustomerResponse>> getListByParam(@RequestBody QueryCustomerRequest request) {
        return Response.success(dealerCustomerService.getListByParam(request));
    }

    /**
     * 根据条件查询对象Page记录
     *
     * @param request
     * @return 查询结果
     */
    @ApiOperation(value = "DealerCustomer管理-根据条件查询对象Page记录接口", httpMethod = "POST", response = Response.class, notes = "get_page_by_param")
    @RequestMapping(value = "/get_page_by_param", method = RequestMethod.POST)
    public Response<PageResponse<CustomerResponse>> getPageByParam(@RequestBody PageRequest<QueryCustomerRequest> request) {
        PageResponse<DealerCustomer> dealerCustomerPageResponse = dealerCustomerService.getPageByParam(DealerCustomerAssembler.transformVOToPOPage(request, DealerCustomer.class));
        return Response.success(DealerCustomerAssembler.transformPOToResponseVoPage(dealerCustomerPageResponse, CustomerResponse.class));
    }

    /**
     * 根据条件查询单个对象
     *
     * @param request
     * @return 查询结果
     */
    @ApiOperation(value = "DealerCustomer管理-根据条件查询单个对象接口", httpMethod = "POST", response = Response.class, notes = "get_page_by_param")
    @RequestMapping(value = "/get_one_by_param", method = RequestMethod.POST)
    public Response<CustomerResponse> getOneByParam(@RequestBody QueryCustomerRequest request) {
        return Response.success(dealerCustomerService.getOneByParam(request));
    }



    /**
     * 查询顾客可绑定客户列表
     *
     * @param: id
     * @return: DealerCustomer对象
     */
    @ApiOperation(value = "查询顾客可绑定客户列表", httpMethod = "GET", response = Response.class, notes = "findCustomerBaseList")
    @RequestMapping(path = "/findCustomerBaseList", method = RequestMethod.GET)
    public  Response<List<CustomerBaseResponse>>  findCustomerBaseList(){
        return Response.success(dealerCustomerService.findCustomerBaseList());
    }



    /**
     *  绑定主数据客户
     *
     * @param updateCustomer
     * @return 绑定成功与否
     */
    @ApiOperation(value = "绑定主数据客户", httpMethod = "POST", response = Response.class, notes = "bindingCustomer")
    @RequestMapping(value = "/bindingCustomer", method = RequestMethod.POST)
    public  Response<Boolean> bindingCustomer(@RequestBody UpdateCustomerRequest updateCustomer) {
        return Response.success(dealerCustomerService.bindingCustomer(updateCustomer));
    }

    /**
     *  绑定主数据客户-待办
     *
     * @param updateCustomer
     * @return 绑定成功与否
     */
    @ApiOperation(value = "绑定主数据客户-待办", httpMethod = "POST", response = Response.class, notes = "bindingCustomer")
    @RequestMapping(value = "/bindingCustomerTodo", method = RequestMethod.POST)
    public  Response<Boolean> bindingCustomerTodo(@RequestBody UpdateCustomerRequest updateCustomer) {
        return Response.success(dealerCustomerService.bindingCustomerTodo(updateCustomer));
    }

    /**
     * 查询总部或者经销商跟进未绑定客户列表
     * @param request
     * @return
     */
    @ApiOperation(value = "查询总部或者经销商跟进未绑定客户列表", httpMethod = "POST", response = Response.class, notes = "findOemOrDealerCusUnbind")
    @RequestMapping(value = "/findOemOrDealerCusUnbind", method = RequestMethod.POST)
    public Response<List<CusUnbindResponse>> findOemOrDealerCusUnbind(@RequestBody CusUnbindRequest request) {
        return Response.success(dealerCustomerService.findOemOrDealerCusUnbind(request));
    }


    /**
     * 根据外部联系人id查看是否已绑定，是否自己跟进
     *
     * @param: id
     * @return: DealerCustomer对象
     */
    @ApiOperation(value = "根据外部联系人id查看是否已绑定，是否自己跟进", httpMethod = "GET", response = Response.class, notes = "cusIsBinging")
    @RequestMapping(path = "/cusIsBinging", method = RequestMethod.GET)
    public  Response<Integer>  cusIsBinging(@RequestParam String externalUserid){
        return Response.success(dealerCustomerService.cusIsBinging(externalUserid));
    }

    @ApiOperation(value = "DealerCustomer管理-根据手机号查询客户信息", httpMethod = "POST", response = Response.class, notes = "getCustomerInfoWithPhone")
    @RequestMapping(path = "/getCustomerInfoWithPhone", method = RequestMethod.POST)
    public Response<CustomerWithExtResponse> getCustomerInfoWithPhone(@RequestBody QueryCustomerRequest request){
        BasePropertyInjection.savePropertyInjection(request);
        String empId= SearchLocalHeader.getHeader(SCRMRequestHeaderEnum.HEADER_EMP_ID.getCode());
        request.setFollowEmpId(Long.valueOf(empId));
        CustomerWithExtResponse cusRes= dealerCustomerService.getCustomerInfoWithPhone(request);
        return Response.success(cusRes);
    }


    /**
     * 跟进empid查询线索
     *
     * @param: id
     * @return: DealerCustomer对象
     */
    @ApiOperation(value = "跟进empid查询线索", httpMethod = "GET", response = Response.class, notes = "findClueByEmpId")
    @RequestMapping(path = "/findClueByEmpId", method = RequestMethod.GET)
    public  Response<Integer>  findClueByEmpId(@RequestParam Long empId){
        return Response.success(dealerCustomerService.findClueByEmpId(empId));
    }
}